<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Performs any connection upkeep checks</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.curl-unescape.html">« curl_unescape</a></li>
      <li style="float: right;"><a href="function.curl-version.html">curl_version »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.curl.html">cURL 函数</a></li>
    <li>Performs any connection upkeep checks</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.curl_upkeep" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">curl_upkeep</h1>
  <p class="verinfo">(PHP 8 &gt;= 8.2.0)</p><p class="refpurpose"><span class="refname">curl_upkeep</span> &mdash; <span class="dc-title">Performs any connection upkeep checks</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.curl_upkeep-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>curl_upkeep</strong></span>(<span class="methodparam"><span class="type"><a href="class.curlhandle.html" class="type CurlHandle">CurlHandle</a></span> <code class="parameter">$handle</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Available if built against libcurl &gt;= 7.62.0.
  </p>
  <p class="para">
   Some protocols have &quot;connection upkeep&quot; mechanisms.
   These mechanisms usually send some traffic on existing connections in order to keep them alive;
   this can prevent connections from being closed due to overzealous firewalls, for example.
  </p>
  <p class="para">
   Connection upkeep is currently available only for HTTP/2 connections.
   A small amount of traffic is usually sent to keep a connection alive.
   HTTP/2 maintains its connection by sending a HTTP/2 PING frame.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.curl_upkeep-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    <dt>
<code class="parameter">handle</code>
</dt>
<dd>
<p class="para">由 <span class="function"><a href="function.curl-init.html" class="function">curl_init()</a></span> 返回的 cURL 句柄。</p></dd>

   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.curl_upkeep-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.curl_upkeep-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4215">
    <p><strong>示例 #1 <span class="function"><strong>curl_upkeep()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$url&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"https://example.com"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$ch&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">curl_init</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_URL</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$url</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_RETURNTRANSFER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_HTTP_VERSION</span><span style="color: #007700">,</span><span style="color: #0000BB">CURL_HTTP_VERSION_2_0</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_SSL_VERIFYPEER</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">curl_setopt</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">CURLOPT_UPKEEP_INTERVAL_MS</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">200</span><span style="color: #007700">);<br />if&nbsp;(</span><span style="color: #0000BB">curl_exec</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">usleep</span><span style="color: #007700">(</span><span style="color: #0000BB">300</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">curl_upkeep</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">));<br />}<br /></span><span style="color: #0000BB">curl_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$ch</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.curl_upkeep-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.curl-init.html" class="function" rel="rdfs-seeAlso">curl_init()</a> - 初始化 cURL 会话</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>